﻿
intimidated_from_faction_modifier = {
	modifier = {
		desc = "FACTION_REASON_INTIMIDATED"
		add = {
			if = {
				limit = {
					$POWER$ < $THRESHOLD$
				}
				add = -50 # Notable deterrent, but Intimidated vassals should still join Factions if they hate you enough.
			}
		}
		has_dread_level_towards = {
			target = $TARGET$
			level = 1
		}
	}
	modifier = {
		desc = "FACTION_REASON_TERRIFIED"
		add = {
			if = {
				limit = {
					$POWER$ < $THRESHOLD$
				}
				add = -1000 # Effectively a full blocker — Terrified vassals should never join Factions until they are powerful enough
			}
			else = {
				add = -100
			}
		}
		has_dread_level_towards = {
			target = $TARGET$
			level = 2
		}
	}
}

legalism_virtue_and_sin_modifier = {
	# Virtues
	modifier = {
		desc = "FACTION_REASON_LEGALISM_VIRTUES"
		add = {
			subtract = $SCORE_PER_TRAIT$
			multiply = $TARGET$.num_virtuous_traits
			if = {
				limit = {
					$TARGET$ = {
						has_trait = zealous
					}
				}
				multiply = 2
			}
			else_if = {
				limit = {
					$TARGET$ = {
						has_trait = cynical
					}
				}
				multiply = 0.5
			}
		}
		$TARGET$ = {
			faith = {
				has_doctrine_parameter = legalism_reduced_faction_virtues
			}
		}
	}

	# Sins
	modifier = {
		desc = "FACTION_REASON_LEGALISM_SINS"
		add = {
			add = $SCORE_PER_TRAIT$
			multiply = $TARGET$.num_sinful_traits
			if = {
				limit = {
					$TARGET$ = {
						has_trait = zealous
					}
				}
				multiply = 2
			}
			else_if = {
				limit = {
					$TARGET$ = {
						has_trait = cynical
					}
				}
				multiply = 0.5
			}
		}
		$TARGET$ = {
			faith = {
				has_doctrine_parameter = legalism_increased_faction_sins
			}
		}

	}
}

pluralism_fundamentalism_modifier = {
	modifier = {
		desc = "FACTION_REASON_PLURALISM_ASTRAY"
		add = {
			value = $ASTRAY_BASE_VALUE$
			# Base opinion multiplier from pluralism
			if = {
				limit = {
					$TARGET$.faith = { has_doctrine = doctrine_pluralism_righteous }
				}
				multiply = hostility_multiplier_righteous
			}
			else_if = {
				limit = {
					$TARGET$.faith = { has_doctrine = doctrine_pluralism_pluralistic }
				}
				multiply = hostility_multiplier_pluralism
			}
			else_if = {
				limit = {
					$TARGET$.faith = { has_doctrine = doctrine_pluralism_fundamentalist }
				}
				multiply = hostility_multiplier_fundamentalist
			}

			#Additional opinion multiplier from adaptive
			if = {
				limit = {
					$TARGET$.faith = { has_doctrine_parameter = reduced_vassal_religion_discontent }
				}
				add = {
					value = $ASTRAY_BASE_VALUE$
					multiply = hostility_multiplier_reduction_adaptive
				}
			}
		}
		NOT = {
			has_active_diarch_for_factions_trigger = { TARGET = $TARGET$ }
		}
		$BASE_FAITH$ = {
			faith_hostility_level = {
				target = $TARGET$.faith
				value = faith_astray_level
			}
		}
		NOT = {
			root.culture = {
				has_cultural_parameter = doesnt_care_about_culture_faith_in_factions
			}
		}
	}
	modifier = {
		desc = "FACTION_REASON_PLURALISM_HOSTILE"
		add = {
			value = $HOSTILE_BASE_VALUE$
			if = {
				limit = {
					$TARGET$.faith = { has_doctrine = doctrine_pluralism_righteous }
				}
				multiply = hostility_multiplier_righteous
			}
			else_if = {
				limit = {
					$TARGET$.faith = { has_doctrine = doctrine_pluralism_pluralistic }
				}
				multiply = hostility_multiplier_pluralism
			}
			else_if = {
				limit = {
					$TARGET$.faith = { has_doctrine = doctrine_pluralism_fundamentalist }
				}
				multiply = hostility_multiplier_fundamentalist
			}

			#Additional opinion multiplier from adaptive
			if = {
				limit = {
					$TARGET$.faith = { has_doctrine_parameter = reduced_vassal_religion_discontent }
				}
				add = {
					value = $ASTRAY_BASE_VALUE$
					multiply = hostility_multiplier_reduction_adaptive
				}
			}
		}
		NOT = {
			has_active_diarch_for_factions_trigger = { TARGET = $TARGET$ }
		}
		$BASE_FAITH$ = {
			faith_hostility_level = {
				target = $TARGET$.faith
				value = faith_hostile_level
			}
		}
		NOT = {
			root.culture = {
				has_cultural_parameter = doesnt_care_about_culture_faith_in_factions
			}
		}
	}
	modifier = {
		desc = "FACTION_REASON_PLURALISM_EVIL"
		add = {
			value = $EVIL_BASE_VALUE$
			if = {
				limit = {
					$TARGET$.faith = { has_doctrine = doctrine_pluralism_righteous }
				}
				multiply = hostility_multiplier_righteous
			}
			else_if = {
				limit = {
					$TARGET$.faith = { has_doctrine = doctrine_pluralism_pluralistic }
				}
				multiply = hostility_multiplier_pluralism
			}
			else_if = {
				limit = {
					$TARGET$.faith = { has_doctrine = doctrine_pluralism_fundamentalist }
				}
				multiply = hostility_multiplier_fundamentalist
			}

			#Additional opinion multiplier from adaptive
			if = {
				limit = {
					$TARGET$.faith = { has_doctrine_parameter = reduced_vassal_religion_discontent }
				}
				add = {
					value = $ASTRAY_BASE_VALUE$
					multiply = hostility_multiplier_reduction_adaptive
				}
			}
		}
		NOT = {
			has_active_diarch_for_factions_trigger = { TARGET = $TARGET$ }
		}
		$BASE_FAITH$ = {
			faith_hostility_level = {
				target = $TARGET$.faith
				value = faith_evil_level
			}
		}
		NOT = {
			root.culture = {
				has_cultural_parameter = doesnt_care_about_culture_faith_in_factions
			}
		}
	}
}

pluralism_fundamentalism_dual_modifier = {
	modifier = {
		desc = "FACTION_REASON_PLURALISM_ASTRAY"
		add = {
			value = $ASTRAY_BASE_VALUE$
			# Base opinion multiplier from pluralism
			if = {
				limit = {
					OR = {
						$TARGET$.faith = { has_doctrine = doctrine_pluralism_righteous }
						$TARGET$.diarch.faith = { has_doctrine = doctrine_pluralism_righteous }
					}
				}
				multiply = hostility_multiplier_righteous
			}
			else_if = {
				limit = {
					OR = {
						$TARGET$.faith = { has_doctrine = doctrine_pluralism_pluralistic }
						$TARGET$.diarch.faith = { has_doctrine = doctrine_pluralism_pluralistic }
					}
				}
				multiply = hostility_multiplier_pluralism
			}
			else_if = {
				limit = {
					OR = {
						$TARGET$.faith = { has_doctrine = doctrine_pluralism_fundamentalist }
						$TARGET$.diarch.faith = { has_doctrine = doctrine_pluralism_fundamentalist }
					}
				}
				multiply = hostility_multiplier_fundamentalist
			}

			#Additional opinion multiplier from adaptive
			if = {
				limit = {
					OR = {
						$TARGET$.faith = { has_doctrine_parameter = reduced_vassal_religion_discontent }
						$TARGET$.diarch.faith = { has_doctrine_parameter = reduced_vassal_religion_discontent }
					}
				}
				add = {
					value = $ASTRAY_BASE_VALUE$
					multiply = hostility_multiplier_reduction_adaptive
				}
			}
		}
		has_active_diarch_for_factions_trigger = { TARGET = $TARGET$ }
		OR = {
			$BASE_FAITH$ = {
				faith_hostility_level = {
					target = $TARGET$.faith
					value = faith_astray_level
				}
			}
			$BASE_FAITH$ = {
				faith_hostility_level = {
					target = $TARGET$.diarch.faith
					value = faith_astray_level
				}
			}
		}
		NOT = {
			root.culture = {
				has_cultural_parameter = doesnt_care_about_culture_faith_in_factions
			}
		}
	}
	modifier = {
		desc = "FACTION_REASON_PLURALISM_HOSTILE"
		add = {
			value = $HOSTILE_BASE_VALUE$
			if = {
				limit = {
					OR = {
						$TARGET$.faith = { has_doctrine = doctrine_pluralism_righteous }
						$TARGET$.diarch.faith = { has_doctrine = doctrine_pluralism_righteous }
					}
				}
				multiply = hostility_multiplier_righteous
			}
			else_if = {
				limit = {
					OR = {
						$TARGET$.faith = { has_doctrine = doctrine_pluralism_pluralistic }
						$TARGET$.diarch.faith = { has_doctrine = doctrine_pluralism_pluralistic }
					}
				}
				multiply = hostility_multiplier_pluralism
			}
			else_if = {
				limit = {
					OR = {
						$TARGET$.faith = { has_doctrine = doctrine_pluralism_fundamentalist }
						$TARGET$.diarch.faith = { has_doctrine = doctrine_pluralism_fundamentalist }
					}
				}
				multiply = hostility_multiplier_fundamentalist
			}

			#Additional opinion multiplier from adaptive
			if = {
				limit = {
					OR = {
						$TARGET$.faith = { has_doctrine_parameter = reduced_vassal_religion_discontent }
						$TARGET$.diarch.faith = { has_doctrine_parameter = reduced_vassal_religion_discontent }
					}
				}
				add = {
					value = $ASTRAY_BASE_VALUE$
					multiply = hostility_multiplier_reduction_adaptive
				}
			}
		}
		has_active_diarch_for_factions_trigger = { TARGET = $TARGET$ }
		OR = {
			$BASE_FAITH$ = {
				faith_hostility_level = {
					target = $TARGET$.faith
					value = faith_hostile_level
				}
			}
			$BASE_FAITH$ = {
				faith_hostility_level = {
					target = $TARGET$.diarch.faith
					value = faith_hostile_level
				}
			}
		}
		NOT = {
			root.culture = {
				has_cultural_parameter = doesnt_care_about_culture_faith_in_factions
			}
		}
	}
	modifier = {
		desc = "FACTION_REASON_PLURALISM_EVIL"
		add = {
			value = $EVIL_BASE_VALUE$
			if = {
				limit = {
					OR = {
						$TARGET$.faith = { has_doctrine = doctrine_pluralism_righteous }
						$TARGET$.diarch.faith = { has_doctrine = doctrine_pluralism_righteous }
					}
				}
				multiply = hostility_multiplier_righteous
			}
			else_if = {
				limit = {
					OR = {
						$TARGET$.faith = { has_doctrine = doctrine_pluralism_pluralistic }
						$TARGET$.diarch.faith = { has_doctrine = doctrine_pluralism_pluralistic }
					}
				}
				multiply = hostility_multiplier_pluralism
			}
			else_if = {
				limit = {
					OR = {
						$TARGET$.faith = { has_doctrine = doctrine_pluralism_fundamentalist }
						$TARGET$.diarch.faith = { has_doctrine = doctrine_pluralism_fundamentalist }
					}
				}
				multiply = hostility_multiplier_fundamentalist
			}

			#Additional opinion multiplier from adaptive
			if = {
				limit = {
					OR = {
						$TARGET$.faith = { has_doctrine_parameter = reduced_vassal_religion_discontent }
						$TARGET$.diarch.faith = { has_doctrine_parameter = reduced_vassal_religion_discontent }
					}
				}
				add = {
					value = $ASTRAY_BASE_VALUE$
					multiply = hostility_multiplier_reduction_adaptive
				}
			}
		}
		has_active_diarch_for_factions_trigger = { TARGET = $TARGET$ }
		OR = {
			$BASE_FAITH$ = {
				faith_hostility_level = {
					target = $TARGET$.faith
					value = faith_evil_level
				}
			}
			$BASE_FAITH$ = {
				faith_hostility_level = {
					target = $TARGET$.diarch.faith
					value = faith_evil_level
				}
			}
		}
		NOT = {
			root.culture = {
				has_cultural_parameter = doesnt_care_about_culture_faith_in_factions
			}
		}
	}
}

liege_debt_modifier = {
	modifier = {
		desc = "FACTION_REASON_LIEGE_DEBT"
		$TARGET$ = { gold <= 0 }
		add = {
			value = 0
			if = {
				limit = { $TARGET$ = { debt_level = 0 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 1
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 1 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 2
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 2 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 3
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 3 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 4
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 4 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 5
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 5 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 6
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 6 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 7
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 7 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 8
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 8 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 9
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 9 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 10
			}
		}
	}
}

debt_modifier = {
	modifier = {
		desc = "REASON_DEBT"
		$TARGET$ = { gold <= 0 }
		add = {
			value = 0
			if = {
				limit = { $TARGET$ = { debt_level = 0 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 1
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 1 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 2
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 2 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 3
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 3 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 4
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 4 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 5
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 5 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 6
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 6 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 7
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 7 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 8
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 8 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 9
			}
			else_if = {
				limit = { $TARGET$ = { debt_level = 9 }}
				add = $SCORE_PER_DEBT_LEVEL$
				multiply = 10
			}
		}
	}
}

dynamic_power_threshold_scripted_modifier = {
	#Lower the threshold depending on the state of other factions
	#Check if the factions types passed in parameter are:
	#Is at war: -20
	#Exists and is above its power theshold: -10
	#Exists and is below its power theshold: -5
	modifier = {
		add = {
			value = 0

			if = {
				limit = {
					faction_target = {
						any_targeting_faction = {
							faction_is_type = $FACTION_TYPE1$
							faction_is_at_war = yes
						}
					}
				}
				add = -20
			}
			else_if = {
				limit = {
					faction_target = {
						any_targeting_faction = {
							faction_is_type = $FACTION_TYPE1$
							faction_is_at_war = no
							faction_power >= faction_power_threshold
						}
					}
				}
				add = -10
			}
			else_if = {
				limit = {
					faction_target = {
						any_targeting_faction = {
							faction_is_type = $FACTION_TYPE1$
							faction_is_at_war = no
						}
					}
				}
				add = -5
			}

			if = {
				limit = {
					faction_target = {
						any_targeting_faction = {
							faction_is_type = $FACTION_TYPE2$
							faction_is_at_war = yes
						}
					}
				}
				add = -20
			}
			else_if = {
				limit = {
					faction_target = {
						any_targeting_faction = {
							faction_is_type = $FACTION_TYPE2$
							faction_is_at_war = no
							faction_power >= faction_power_threshold
						}
					}
				}
				add = -10
			}
			else_if = {
				limit = {
					faction_target = {
						any_targeting_faction = {
							faction_is_type = $FACTION_TYPE2$
							faction_is_at_war = no
						}
					}
				}
				add = -5
			}

			if = {
				limit = {
					faction_target = {
						any_targeting_faction = {
							faction_is_type = $FACTION_TYPE3$
							faction_is_at_war = yes
						}
					}
				}
				add = -20
			}
			else_if = {
				limit = {
					faction_target = {
						any_targeting_faction = {
							faction_is_type = $FACTION_TYPE3$
							faction_is_at_war = no
							faction_power >= faction_power_threshold
						}
					}
				}
				add = -10
			}
			else_if = {
				limit = {
					faction_target = {
						any_targeting_faction = {
							faction_is_type = $FACTION_TYPE3$
							faction_is_at_war = no
						}
					}
				}
				add = -5
			}
			#security to never reach a power threshold equals to 0
			min = -70
		}
		desc = "FACTION_POWER_INTERNAL_ISSUES"
	}
}

common_discontent_progress_modifier = {
	# We use a modifier as our base progress in order to take advantage of script values.
	modifier = {
		add = base_discontent_progress
		desc = "BASE_COLON"
	}

	# The higher above the power threshold the faction is, the faster discontent increases.
	modifier = {
		faction_power > faction_power_threshold
		add = faction_discontent_for_extra_power
		desc = "FACTION_DISCONTENT_POWER_ABOVE_THRESHOLD"
	}

	# Discontent slowly decays if power is under the threshold.
	modifier = {
		faction_power < faction_power_threshold
		add = {
			add = base_discontent_progress
			multiply = -2
		}
		desc = "FACTION_DISCONTENT_POWER_BELOW_THRESHOLD"
	}
}

common_create_faction_blockers = {
	# Refuses to make if there was a recent independence faction revolt.
	modifier = {
		add = -1000
		$FACTION_TARGET$ = {
			has_character_flag = $FLAG$
		}
	}

	# Do not join a new faction if I am already at war.
	modifier = {
		add = -1000
		is_at_war = yes
	}

	# Block characters from joining if they have a high opinion of the target
	modifier = {
		add = -1000
		save_temporary_opinion_value_as = { name = target_opinion target = $FACTION_TARGET$ }
		scope:target_opinion >= 80
	}

	# Admin empire should not face new factions during ongoing faction wars
	modifier = {
		add = -1000
		$FACTION_TARGET$ = {
			government_allows = administrative
			any_targeting_faction = { faction_is_at_war = yes }
		}
	}

	# ACH host intent reward
	modifier = {
		add = -1000
		has_character_modifier = ach_intent_faction_joining_prevention_modifier
	}
}

common_join_faction_blockers = {
	# Do not join a new faction if I am already at war.
	modifier = {
		add = -1000
		AND = {
			is_at_war = yes
			trigger_if = {
				limit = {
					exists = joined_faction
				}
				NOT = { joined_faction = scope:faction }
			}
		}
	}

	modifier = {
		add = -1000
		save_temporary_opinion_value_as = { name = target_opinion target = $FACTION_TARGET$ }
		scope:target_opinion >= 80
	}

	# ACH host intent reward
	modifier = {
		add = -1000
		has_character_modifier = ach_intent_faction_joining_prevention_modifier
	}
}

common_faction_modifiers = {
	# +/- 40 join weight at -/+100 opinion
	opinion_modifier = {
		who = root
		opinion_target = $FACTION_TARGET$
		multiplier = $OPINION_MULTIPLIER$
		max = $MAX_OPINION$
	}

	# for each character.religion != factionTarget.religion add X join-score
	pluralism_fundamentalism_modifier = {
		ASTRAY_BASE_VALUE = 25
		HOSTILE_BASE_VALUE = 50
		EVIL_BASE_VALUE = 100
		BASE_FAITH = faith
		TARGET = $FACTION_TARGET$
	}

	# +25 join chance per sin, -25 join chance per virtue
	legalism_virtue_and_sin_modifier = {
		TARGET = $FACTION_TARGET$
		SCORE_PER_TRAIT = 25
	}

	# -100 join chance from intimidation, -1000 join chance from terrified. This modifier doesn't apply if a faction is above the power threshold
	intimidated_from_faction_modifier = {
		TARGET = $FACTION_TARGET$
		POWER =  $POWER$
		THRESHOLD = $THRESHOLD$
	}

	# Unity - House members are less likely to join factions against each other with high levels of unity
	modifier = { # Friendly unity level
		desc = "FACTION_REASON_unity_less_likely_claimant_factions"
		add = -20
		exists = root.house
		exists = $FACTION_TARGET$.house
		house = $FACTION_TARGET$.house
		house = {
			has_house_unity_parameter = unity_less_likely_factions
		}
	}
	modifier = { # Harmonious unity level
		desc = "FACTION_REASON_unity_significantly_less_likely_claimant_factions"
		add = -40
		exists = root.house
		exists = $FACTION_TARGET$.house
		house = $FACTION_TARGET$.house
		house = {
			has_house_unity_parameter = unity_significantly_less_likely_factions
		}
	}

	# Debt: +10 to +60 join chance depending on how far in debt the top liege is
	liege_debt_modifier = {
		TARGET = $FACTION_TARGET$
		SCORE_PER_DEBT_LEVEL = 10
	}

	# Duty Focus
	modifier = {
		desc = FACTION_REASON_duty_focus
		add = duty_focus_value
		$FACTION_TARGET$ = {
			has_focus = stewardship_duty_focus
		}
	}

	# Court Position Task
	modifier = {
		desc = FACTION_REASON_court_position_task
		add = duty_focus_value
		$FACTION_TARGET$ = {
			has_variable = court_position_faction_commitment_task
		}
	}

	# Difficulty Settings
	modifier = { # Easy
		desc = "FACTION_REASON_DIFFICULTY_EASY"
		add = -50
		has_game_rule = easy_difficulty
		$FACTION_TARGET$ = {
			is_ai = no
		}
	}
	modifier = { # Very Easy
		desc = "FACTION_REASON_DIFFICULTY_VERY_EASY"
		add = -150
		has_game_rule = very_easy_difficulty
		$FACTION_TARGET$ = {
			is_ai = no
		}
	}
	modifier = { # Hard
		desc = "FACTION_REASON_DIFFICULTY_HARD"
		add = -100
		has_game_rule = hard_difficulty
		$FACTION_TARGET$ = {
			is_ai = yes
		}
	}
	modifier = { # Very Hard
		desc = "FACTION_REASON_DIFFICULTY_VERY_HARD"
		add = -200
		has_game_rule = very_hard_difficulty
		$FACTION_TARGET$ = {
			is_ai = yes
		}
	}
	modifier = { # Hard, high opinion of player
		desc = "game_rule_base_value"
		add = 50
		has_game_rule = hard_difficulty
		$FACTION_TARGET$ = {
			is_ai = no
		}
		opinion = {
			target = $FACTION_TARGET$
			value > 25
		}
	}
	modifier = { # Very Hard, high opinion of player
		desc = "game_rule_base_value"
		add = 75
		has_game_rule = very_hard_difficulty
		$FACTION_TARGET$ = {
			is_ai = no
		}
		opinion = {
			target = $FACTION_TARGET$
			value > 25
		}
	}
	modifier = { # Hard, low opinion of player
		desc = "game_rule_base_value"
		add = 100
		has_game_rule = hard_difficulty
		$FACTION_TARGET$ = {
			is_ai = no
		}
		opinion = {
			target = $FACTION_TARGET$
			value <= 25
		}
	}
	modifier = { # Very Hard, low opinion of player
		desc = "game_rule_base_value"
		add = 150
		has_game_rule = very_hard_difficulty
		$FACTION_TARGET$ = {
			is_ai = no
		}
		opinion = {
			target = $FACTION_TARGET$
			value <= 25
		}
	}
	modifier = { # Conquerors
		desc = "NO_FRIVOLOUS_ACTIVITIES_REASON"
		add = -100
		$FACTION_TARGET$ = {
			ai_should_get_conqueror_bonuses = yes
		}
	}
	modifier = { # Conquerors
		desc = "NO_FRIVOLOUS_ACTIVITIES_REASON"
		add = -250
		$FACTION_TARGET$ = {
			ai_should_get_extreme_conqueror_bonuses = yes
		}
	}
		
	# Nomads - Obedient characters less likely to create factions
	modifier = {
		desc = "MPO_OBEDIENT_NOMAD"
		is_obedient_to = $FACTION_TARGET$
		$FACTION_TARGET$ = { government_has_flag = government_is_nomadic }
		add = -75
	}
		
	# Nomads - But disobedient characters are more likely to cause trouble...
	modifier = {
		desc = "MPO_NON_OBEDIENT_NOMAD"
		obedience_target = $FACTION_TARGET$
		NOT = {
			is_obedient_to = $FACTION_TARGET$
		}
		$FACTION_TARGET$ = { government_has_flag = government_is_nomadic }
		add = 75
	}
	
	modifier = {
		$FACTION_TARGET$ = {
			any_memory = { 
				has_memory_type = nomad_showed_weakness_in_war
			}
		}
		
		add = {
			value = 25
			if = {
				limit = {
					$FACTION_TARGET$ = { 
						any_memory = { 
							has_memory_type = nomad_showed_weakness_in_war
							memory_age_years < 10
						}
					}
				}
				add = 75
			}
		}
		desc = cease_tribute_showed_weakness_in_war_reason
	}

	modifier = {
		$FACTION_TARGET$ = {
			any_memory = { 
				has_memory_type = had_chaotic_kurultai_succession
			}
		}
		add = {
			value = 25
			if = {
				limit = {
					$FACTION_TARGET$ = { 
						any_memory = { 
							has_memory_type = had_chaotic_kurultai_succession
							memory_age_years < 10
						}
					}
				}
				add = 75
			}
		}
		desc = cease_tribute_had_chaotic_kurultai_succession_reason
	}

	# Realm Stability Settings
	modifier = {
		desc = "FACTION_REASON_GAME_RULE_REALM_STABILITY_LESSER"
		add = 50
		has_game_rule = lesser_realm_stability
	}
	modifier = {
		desc = "FACTION_REASON_GAME_RULE_REALM_STABILITY_HIGHER"
		add = -50
		has_game_rule = higher_realm_stability
	}
	modifier = {
		desc = "FACTION_REASON_GAME_RULE_REALM_STABILITY_EXTREME"
		add = -100
		has_game_rule = extreme_realm_stability
	}
	modifier = {
		desc = "FACTION_REASON_GAME_RULE_REALM_STABILITY_LESSER"
		add = 50
		has_game_rule = lesser_realm_stability_ai_only
		$FACTION_TARGET$ = {
			is_ai = yes
		}
	}
	modifier = {
		desc = "FACTION_REASON_GAME_RULE_REALM_STABILITY_HIGHER"
		add = -50
		has_game_rule = higher_realm_stability_ai_only
		$FACTION_TARGET$ = {
			is_ai = yes
		}
	}
	modifier = {
		desc = "FACTION_REASON_GAME_RULE_REALM_STABILITY_EXTREME"
		add = -100
		has_game_rule = extreme_realm_stability_ai_only
		$FACTION_TARGET$ = {
			is_ai = yes
		}
	}
	modifier = {
		desc = "FACTION_REASON_GAME_RULE_REALM_STABILITY_LESSER"
		add = 50
		has_game_rule = lesser_realm_stability_regular_factions
	}
	modifier = {
		desc = "FACTION_REASON_GAME_RULE_REALM_STABILITY_HIGHER"
		add = -50
		has_game_rule = higher_realm_stability_regular_factions
	}
	modifier = {
		desc = "FACTION_REASON_GAME_RULE_REALM_STABILITY_EXTREME"
		add = -100
		has_game_rule = extreme_realm_stability_regular_factions
	}
	modifier = {
		desc = "FACTION_REASON_GAME_RULE_REALM_STABILITY_LESSER"
		add = 50
		has_game_rule = lesser_realm_stability_regular_factions_ai_only
		$FACTION_TARGET$ = {
			is_ai = yes
		}
	}
	modifier = {
		desc = "FACTION_REASON_GAME_RULE_REALM_STABILITY_HIGHER"
		add = -50
		has_game_rule = higher_realm_stability_regular_factions_ai_only
		$FACTION_TARGET$ = {
			is_ai = yes
		}
	}
	modifier = {
		desc = "FACTION_REASON_GAME_RULE_REALM_STABILITY_EXTREME"
		add = -100
		has_game_rule = extreme_realm_stability_regular_factions_ai_only
		$FACTION_TARGET$ = {
			is_ai = yes
		}
	}

	#safe guard to avoid Factions being created when the game starts
	modifier = {
		add = -10000
		years_from_game_start < 1
		$FACTION_TARGET$.primary_title.tier = tier_duchy
		trigger_if = {
			limit = { exists = scope:actor }
			NOT = { # Not used for already warring factions
				scope:actor.joined_faction ?= {
					exists = faction_war
					faction_target = $FACTION_TARGET$
				}
			}
		}
		desc = "FACTION_REASON_GAME_START_DUCHY"
	}

	modifier = {
		add = -10000
		years_from_game_start < 5
		$FACTION_TARGET$.primary_title.tier = tier_kingdom
		trigger_if = {
			limit = { exists = scope:actor }
			NOT = { # Not used for already warring factions
				scope:actor.joined_faction ?= {
					exists = faction_war
					faction_target = $FACTION_TARGET$
				}
			}
		}
		desc = "FACTION_REASON_GAME_START_KINGDOM"
	}

	modifier = {
		add = -10000
		years_from_game_start < 10
		$FACTION_TARGET$.primary_title.tier = tier_empire
		trigger_if = {
			limit = { exists = scope:actor }
			NOT = { # Not used for already warring factions
				scope:actor.joined_faction ?= {
					exists = faction_war
					faction_target = $FACTION_TARGET$
				}
			}
		}
		desc = "FACTION_REASON_GAME_START_EMPIRE"
	}

	modifier = { # Hostages
		desc = "FACTION_REASON_HOSTAGE"
		add = -50
		any_home_court_hostage = { warden = $FACTION_TARGET$ }
	}

	modifier = {
		desc = "FACTION_REASON_DETRACTORS_STICK_TOGETHER"
		add = -50
		has_trait = fp3_struggle_detractor
		OR = {
			culture = { has_same_culture_heritage = $FACTION_TARGET$.culture }
			faith = $FACTION_TARGET$.faith
		}
		$FACTION_TARGET$ = {
			has_trait = fp3_struggle_detractor
		}
	}

	#FP3 Strengthern Caliphate
	modifier = {
		desc = "FACTION_REASON_FP3_SUPPORTER"
		add = -50
		global_var:fp3_struggle_ending ?= flag:fp3_struggle_strengthen_caliphate_ending
		has_trait = fp3_struggle_supporter
		$FACTION_TARGET$ = { has_title = title:d_sunni }
	}
	modifier = {
		add = 300
		desc = FACTION_REASON_DETRACTOR
		has_variable = detractor_faction
		var:detractor_faction = scope:faction.faction_target
	}
}

independence_faction_create_blockers = {
	# If a suitable Populist Faction already exists, prefer to side with it
	modifier = {
		add = -1000
		$FACTION_TARGET$ = {
			any_targeting_faction = {
  				faction_is_type = populist_faction
  				var:faction_faith = root.faith
  				var:faction_culture = root.culture
			}
	  	}
	}
	modifier = {
		add = -1000
		$FACTION_TARGET$ = {
			any_targeting_faction = {
  				faction_is_type = populist_faction
  				var:faction_faith = root.faith
  				var:faction_culture = { has_same_culture_heritage = root.culture }
			}
	  	}
	}
	modifier = {
		add = -2000
		OR = {
			government_has_flag = government_is_nomadic
			government_has_flag = government_is_tribal
		}
		$FACTION_TARGET$.primary_title = {
			has_title_law = confederation_elective_succession_law
	  	}
	}
	modifier = {
		add = -2000
		government_has_flag = government_is_nomadic
		$FACTION_TARGET$ = {
			any_owned_story = {
				OR = {
					story_type = story_greatest_of_khans
					story_type = story_mongol_invasion
				}
			}
	  	}
	}
}

independence_faction_modifiers = {
	modifier = { # Electors are less likely to join independence factions, if their faith is astray or below
		desc = "FACTION_REASON_ELECTOR"

		add = {
			value = -150
			if = {
				limit = {
					exists = title:e_hre
					$FACTION_TARGET$ = {
						has_primary_title = title:e_hre
					}
				}
				add = -150
			}
		}
		$FACTION_TARGET$.primary_title = {
			has_order_of_succession = election
			any_elector = {
				this = root
			}
		}
		faith = {
			faith_hostility_level = {
				target = $FACTION_TARGET$.faith
				value <= faith_astray_level
			}
		}
	}

	# Liege is not my Rightful Liege or a consequent par of my Realm is outside of their De Jure
	modifier = {
		desc = "FACTION_REASON_RIGHTFUL"
		add = {
			value = 125
			# Larger realms are inherently more rebellious.
			add = {
				value = sub_realm_size
				multiply = 2
			}
		}
		OR = {
	 		NOT = {
	 			$FACTION_TARGET$ = { is_rightful_liege_of = root }
			}
			any_sub_realm_county = {
				percent <= 0.5
				save_temporary_scope_as = current_county
				$FACTION_TARGET$.primary_title = {
					any_in_de_jure_hierarchy = {
						this = scope:current_county
					}
				}
			}
		}
	}

	# Kingdoms gain an additional boost to independence, as they don't like being under the thumb of others.
	modifier = {
		desc = "FACTION_REASON_KING"
		add = { # High-grandeur Kings will want independence even more
			value =	50
			if = {
				limit = {
					has_royal_court = yes
					has_dlc_feature = royal_court
					$FACTION_TARGET$ = {
						has_royal_court = yes
					}
					court_grandeur_current_level > $FACTION_TARGET$.court_grandeur_current_level
				}
				add = {
					add = court_grandeur_current_level
					subtract = $FACTION_TARGET$.court_grandeur_current_level
					multiply = 15
				}
			}
		}
		NOT = { government_allows = administrative } # Admin kings like being vassals, and don't get a boost
		highest_held_title_tier = tier_kingdom
	}

	# Lowers independence wishes from Counts.
	modifier = {
		desc = "FACTION_REASON_COUNT"
		add = -25
		highest_held_title_tier = tier_county
		NOT = { government_has_flag = government_is_nomadic }
	}

	# Toe the Line Perk
	modifier = {
		desc = "FACTION_REASON_PERK_TOE_THE_LINE"
		add = -50
		$FACTION_TARGET$ = {
			has_perk = toe_the_line_perk
		}
	}

	# Stem Duchies innovation
	modifier = {
		desc = "FACTION_REASON_INNOVATION_STEM_DUCHIES"
		add = -25
		$FACTION_TARGET$ = { culture = { has_innovation = innovation_stem_duchies }	}
		culture = { has_same_culture_heritage = $FACTION_TARGET$.culture }
	}

	# Characters are less likely to join if cultural acceptance is high
	modifier = {
		desc = "FACTION_REASON_CULTURE_ACCEPTANCE"
		culture = {
			NOR = {
				this = $FACTION_TARGET$.culture
				cultural_acceptance = { target = $FACTION_TARGET$.culture value >= 90 } # Essentially the same culture
				has_cultural_parameter = doesnt_care_about_culture_faith_in_factions
			}
		}
		add = {
			value = 20
			if = {
				limit = {
					culture = {
						cultural_acceptance = { target = $FACTION_TARGET$.culture value <= 20 }
					}
				}
				add = 20
			}
			if = {
				limit = {
					culture = {
						cultural_acceptance = { target = $FACTION_TARGET$.culture value <= 35 }
					}
				}
				add = 15
			}
			if = {
				limit = {
					culture = {
						cultural_acceptance = { target = $FACTION_TARGET$.culture value <= 50 }
					}
				}
				add = 10
			}
			if = {
				limit = {
					culture = {
						cultural_acceptance = { target = $FACTION_TARGET$.culture value <= 70 }
					}
				}
				add = 5
			}
			if = {
				limit = {
					culture = {
						cultural_acceptance = { target = $FACTION_TARGET$.culture value <= 80 }
					}
				}
				add = 5
			}
			if = { # The liege knowing your language cuts this penalty in half
				limit = {
					$FACTION_TARGET$ = {
						knows_language_of_culture = prev.culture
					}
				}
				multiply = 0.5
			}
		}
	}

	# If in struggle, rather go for Dissolution faction
	modifier = {
		desc = "FACTION_REASON_PREFER_DISSOLUTION_FACTION"
		add = {
			value = 0
			# Some phases give a low chance...
#			if = {
#				limit = {
#					$FACTION_TARGET$ = {
#						any_character_struggle = {
#							is_struggle_type = iberian_struggle
#							involvement = involved
#							OR = {
#								is_struggle_phase = struggle_iberia_phase_hostility
#								is_struggle_phase = struggle_iberia_phase_opportunity
#							}
#						}
#					}
#				}
#				add = -100
#			}
		}
		$FACTION_TARGET$ = {
			any_character_struggle = {
				is_struggle_type = iberian_struggle
				involvement = involved
			}
		}
		OR = {
			is_powerful_vassal_of = $FACTION_TARGET$
			$FACTION_TARGET$ = {
				any_targeting_faction = {
					faction_is_type = nation_fracturing_faction
				}
			}
		}
	}

	# Less likely for Anglosaxons to want to destroy England
	modifier = {
		desc = "FACTION_REASON_ANGLOSAXON"
		add = -200
		culture = {
			has_cultural_pillar = heritage_west_germanic
		}
	 	$FACTION_TARGET$.primary_title = title:k_england
	}

	# Less likely for French vassals
	modifier = {
		desc = "FACTION_REASON_FRENCH_VASSAL"
		add = -200
		culture = {
			has_cultural_pillar = heritage_frankish
		}
	 	$FACTION_TARGET$.primary_title = title:k_france
	}

	# New vassals do not want to join independence factions
	modifier = {
		desc = "FACTION_REASON_NEW_VASSAL"
		add = -1000
		has_opinion_modifier = {
			modifier = became_vassal
			target = $FACTION_TARGET$
		}
	}
	
	# Admin vassals are generally want independence a bit less than others
	modifier = {
		desc = "FACTION_REASON_ADMINISTRATIVE"
		add = -25
		government_allows = administrative
	}
	
	# Nomads want to break free from non-nomads badly
	modifier = {
		desc = "FACTION_REASON_NOMADIC"
		add = 150
		government_has_flag = government_is_nomadic
		$FACTION_TARGET$ = {
			NOT = {
				government_has_flag = government_is_nomadic
			}
		}
	}

	# Nomads generally want independence when possible
	# This is intentionally the same as 'rightful liege' and will stack with it
	modifier = {
		desc = "FACTION_REASON_NOMADIC"
		add = {
			value = 125
			# Larger realms are inherently more rebellious.
			add = {
				value = sub_realm_size
				multiply = 2
			}
		}
		government_has_flag = government_is_nomadic
	}
}

nation_fracturing_faction_modifiers = {

	# Short reign increase the change of NF
	modifier = {
		desc = "FACTION_REASON_SHORT_REIGN"
		add = {
			value = 0
			if =  {
				limit =  {
					$FACTION_TARGET$ = {
						primary_title = {
							title_held_years <= 1
						}
					}
				}
				add = 15
			}
			if =  {
				limit =  {
					$FACTION_TARGET$ = {
						primary_title = {
							title_held_years <= 5
						}
					}
				}
				add = 10
			}
			if =  {
				limit =  {
					$FACTION_TARGET$ = {
						primary_title = {
							title_held_years <= 10
						}
					}
				}
				add = 5
			}
		}
	}

	# Lower the score if there are claimants of my culture
	modifier = {
		desc = "FACTION_REASON_CLAIMANTS_OF_MY_CULTURE"
		add = -200
		$FACTION_TARGET$ = {
			primary_title = {
				any_claimant = {
					count > 0
					culture = root.culture
				}
			}
		}
	}

	# Characters are less likely to join if cultural acceptance is high
	modifier = {
		desc = "FACTION_REASON_CULTURAL_ACCEPTANCE"
		culture = {
			NOR = {
				this = $FACTION_TARGET$.culture
				cultural_acceptance = { target = $FACTION_TARGET$.culture value >= 90 } # Essentially the same culture
				has_cultural_parameter = doesnt_care_about_culture_faith_in_factions
			}
		}
		add = {
			value = 10
			if = {
				limit = {
					culture = {
						cultural_acceptance = { target = $FACTION_TARGET$.culture value <= 20 }
					}
				}
				add = 20
			}
			if = {
				limit = {
					culture = {
						cultural_acceptance = { target = $FACTION_TARGET$.culture value <= 35 }
					}
				}
				add = 15
			}
			if = {
				limit = {
					culture = {
						cultural_acceptance = { target = $FACTION_TARGET$.culture value <= 50 }
					}
				}
				add = 10
			}
			if = {
				limit = {
					culture = {
						cultural_acceptance = { target = $FACTION_TARGET$.culture value <= 70 }
					}
				}
				add = 5
			}
			if = {
				limit = {
					culture = {
						cultural_acceptance = { target = $FACTION_TARGET$.culture value <= 80 }
					}
				}
				add = 5
			}
		}
	}

	# More likely to happen if the target don't control the entirety of the de jure area of any of their title of the same rank as their primary title
	modifier = {
		desc = "FACTION_REASON_TARGET_NOT_FULL_CONTROL"
		add = {
			value = 0
			$FACTION_TARGET$ = {
				every_held_title = {
					limit = {
						this.tier = prev.primary_title.tier
						NOT = { $FACTION_TARGET$ = { completely_controls = prev } }
					}
					add = {
						if = {
							limit = { tier = tier_empire }
							add = 50
						}
						else_if = {
							limit = { tier = tier_kingdom }
							add = 20
						}
						else_if = {
							limit = { tier = tier_duchy }
							add = 15
						}
						else_if = {
							limit = { tier = tier_county }
							add = 10
						}
						#bigger penalty for the primary_title
						if = {
							limit = { this = $FACTION_TARGET$.primary_title }
							add = 50
						}
					}
				}
			}
		}
	}

	# more likely to happen if they lost wars or title recently
	modifier = {
		desc = "FACTION_REASON_RECENT_LOST_WAR"
		add = {
			value = 0
			if = {
				limit = { $FACTION_TARGET$ = { has_variable =  recently_lost_wars } }
				add = $FACTION_TARGET$.var:recently_lost_wars
				multiply = 15
			}
		}
	}

	# more likely to happen to Tribal and Clans
	modifier = {
		desc = "FACTION_REASON_TRIBAL_CLAN"
		add = {
			value = 0
			if = {
				limit = {
					$FACTION_TARGET$ = {
						OR = {
							government_has_flag = government_is_tribal
							government_has_flag = government_is_nomadic
						}
					}
				}
				add = 25
			}
			else_if = {
				limit = { $FACTION_TARGET$ = { government_has_flag = government_is_clan } }
				# Increase for each powerful vassal you are not allied with
				add = {
					value = 0
					$FACTION_TARGET$ = {
						every_vassal = {
							limit = {
								is_powerful_vassal_of = $FACTION_TARGET$
								NOT = { is_allied_to = $FACTION_TARGET$ }
							}
							add = 10
						}
					}
				}
			}
		}
	}

	modifier = {
		$FACTION_TARGET$ = { 
			any_memory = { 
				has_memory_type = nomad_showed_weakness_in_war
				memory_age_years < 10
			}
		}
		
		add = {
			value = 125
			add = $FACTION_TARGET$.sub_realm_size
		}
		desc = cease_tribute_showed_weakness_in_war_reason
	}

	modifier = {
		$FACTION_TARGET$ = { 
			any_memory = { 
				has_memory_type = had_chaotic_kurultai_succession
				memory_age_years < 10
			}
		}
		add = {
			value = 125
			add = {
				value = $FACTION_TARGET$.sub_realm_size
				multiply = 2
			}
		}
		desc = cease_tribute_had_chaotic_kurultai_succession_reason
	}

	# motivated if the target is involved in various struggle phases.
	modifier = {
		add = {
			value = 0
			# Some phases give a low chance...
#			if = {
#				limit = {
#					$FACTION_TARGET$ = {
#						any_character_struggle = {
#							is_struggle_type = iberian_struggle
#							involvement = involved
#							is_struggle_phase = struggle_iberia_phase_hostility
#						}
#					}
#				}
#				add = 50
#			}
#			# ... & some phases give a high chance.
#			else_if = {
#				limit = {
#					$FACTION_TARGET$ = {
#						any_character_struggle = {
#							is_struggle_type = iberian_struggle
#							involvement = involved
#							is_struggle_phase = struggle_iberia_phase_opportunity
#						}
#					}
#				}
#				add = 100 # High chance in opportunity
#			}
		}
		$FACTION_TARGET$ = {
			any_character_struggle = {
				is_struggle_type = iberian_struggle
				involvement = involved
			}
		}
	}

	# Less likely for elective title
	modifier = {
		desc = "FACTION_REASON_ELECTIVE_PRIMARY"
		add = -125
	 	$FACTION_TARGET$.primary_title = {
			has_order_of_succession = election
		}
	}

	# Less likely if you have low Crown Authority
	modifier = {
		desc = "FACTION_REASON_LOW_CROWN_AUTHORITY"
		add = -50
	 	$FACTION_TARGET$ = {
			OR = {
				has_realm_law = crown_authority_0
				has_realm_law = crown_authority_1
			}
		}
	}

	# Less likely for French vassals
	modifier = {
		desc = "FACTION_REASON_FRENCH_VASSAL"
		add = -200
		culture = {
			has_cultural_pillar = heritage_frankish
		}
	 	$FACTION_TARGET$.primary_title = title:k_france
	}

	# Less likely for Anglosaxons to want to destroy England
	modifier = {
		desc = "FACTION_REASON_ANGLOSAXON"
		add = -200
		culture = {
			has_cultural_pillar = heritage_west_germanic
		}
	 	$FACTION_TARGET$.primary_title = title:k_england
	}

	# Less likely for Normans to want to destroy England
	modifier = {
		desc = "FACTION_REASON_NORMAN"
		add = -200
		culture = {
			has_cultural_pillar = heritage_frankish
		}
	 	$FACTION_TARGET$.primary_title = title:k_england
	}

	# Less likely for Brythonic to want to destroy England
	modifier = {
		desc = "FACTION_REASON_BRYTHONIC"
		add = -200
		culture = {
			has_cultural_pillar = heritage_brythonic
		}
	 	$FACTION_TARGET$.primary_title = title:k_england
	}

	# Less likely for vassals with Byzantine Traditions
	modifier = {
		desc = "FACTION_REASON_BYZANTINE"
		add = -500
	 	culture = {
			has_cultural_parameter = byzantine_faction_differences
		}
	 	$FACTION_TARGET$ = {
			has_title = title:e_byzantium
		}
	}

	modifier = {
		desc = "FACTION_REASON_BYZANTINE_RELIGION"
		add = -200
		religion = liege.religion
	 	$FACTION_TARGET$ = {
			has_title = title:e_byzantium
		}
	}

	modifier = { # New vassals do not want to join independence factions
		desc = "FACTION_REASON_NEW_VASSAL"
		add = -1000
		has_opinion_modifier = {
			modifier = became_vassal
			target = $FACTION_TARGET$
		}
	}

	modifier = {
		desc = "FACTION_REASON_PERSIAN_STRUGGLE"
		add = -100
		any_character_struggle = {
			is_struggle_type = persian_struggle
		}
	}
}

nation_fracturing_faction_blockers = {
	# If you have a claim on the title, you should create a claimant faction instead
	modifier = {
		add = -1000
		OR = {
			has_weak_claim_on = $FACTION_TARGET$.primary_title
			has_claim_on = $FACTION_TARGET$.primary_title
		}
	}

	# We don't want the AI to create it for a title below Kingdom
	modifier = {
		add = -1000
		$FACTION_TARGET$.primary_title.tier < tier_kingdom
	}
	
	modifier = {
		add = -2000
		OR = {
			government_has_flag = government_is_nomadic
			government_has_flag = government_is_tribal
		}
		$FACTION_TARGET$.primary_title = {
			has_title_law = confederation_elective_succession_law
	  	}
	}
	
	modifier = {
		add = -2000
		government_has_flag = government_is_nomadic
		$FACTION_TARGET$ = {
			any_owned_story = {
				OR = {
					story_type = story_greatest_of_khans
					story_type = story_mongol_invasion
				}
			}
	  	}
	}

	## Game ruler specifics

	# Keep it while the Caliph is alive
	modifier = {
		add = -1000
		$FACTION_TARGET$ = {
			this = character:73683
			any_held_title = {
				this = title:k_andalusia
			}
		}
		has_game_rule = dissolution_after_caliph_death
	}

	# Historical time blocker
	modifier = {
		add = -1000
		current_date < 1020.1.1
		$FACTION_TARGET$ = {
			any_held_title = {
				this = title:k_andalusia
			}
		}
		has_game_rule = dissolution_historical_date
	}
}

liberty_faction_modifiers = {
	modifier = {
		desc = "FACTION_REASON_CROWN_AUTHORITY_1"
		add = 10 # AI won't join at +10 Opinion
		$FACTION_TARGET$ = {
			has_realm_law = crown_authority_1
		}
	}
	modifier = {
		desc = "FACTION_REASON_CROWN_AUTHORITY_2"
		add = 20 # AI won't join at +20 Opinion
		$FACTION_TARGET$ = {
			has_realm_law = crown_authority_2
		}
	}
	modifier = {
		desc = "FACTION_REASON_CROWN_AUTHORITY_3"
		add = 40 # AI won't join at +40 Opinion
		$FACTION_TARGET$ = {
			has_realm_law = crown_authority_3
		}
	}

	# Legacy
	modifier = {
		desc = "FACTION_REASON_GLORY_LEGACY_4"
		add = -20
		$FACTION_TARGET$.dynasty ?= { has_dynasty_perk = glory_legacy_4 }
	}
}

claimant_faction_blockers = {
	# Do not create if I put my current liege on the throne in a different claimant faction.
	modifier = {
		add = -5000
		has_opinion_modifier = {
			modifier = claimant_faction_member_opinion
			target = $FACTION_TARGET$
		}
	}

	# Do not start factions for certain claimants
	modifier = {
		add = -1000
		$FACTION_CLAIMANT$ = {
			OR = {
				has_trait = incapable
				government_has_flag = government_is_theocracy
			}
		}
	}
}

claimant_faction_modifiers = {
	# Gender concerns (general)
	modifier = {
		desc = "FACTION_REASON_CLAIMANT_GENDER"
		add = -50
		NOT = { $FACTION_CLAIMANT$ = root }
		OR = {
			AND = {
				faith = { has_doctrine = doctrine_gender_female_dominated }
				$FACTION_CLAIMANT$ = { is_male = yes }
			}
			AND = {
				faith = { has_doctrine = doctrine_gender_male_dominated }
				$FACTION_CLAIMANT$ = { is_female = yes }
			}
		}
	}

	# Gender concerns (target of wrong gender)
	modifier = {
		desc = "FACTION_REASON_CLAIMANT_GENDER_VS_TARGET"
		add = 25
		OR = {
			AND = {
				faith = { has_doctrine = doctrine_gender_female_dominated }
				$FACTION_TARGET$ = { is_male = yes }
				$FACTION_CLAIMANT$ = {
					is_female = yes
					faith = root.faith
				}
			}
			AND = {
				faith = { has_doctrine = doctrine_gender_male_dominated }
				$FACTION_TARGET$ = { is_female = yes }
				$FACTION_CLAIMANT$ = {
					is_male = yes
					faith = root.faith
				}
			}
		}
	}

	# Powerful vassals will be even more motivated to create claimant if unhappy with liege, if they like the claimant more than their liege
	opinion_modifier = {
		desc = "FACTION_REASON_POWERFUL_LIKES_CLAIMANT_MORE"
		trigger = {
			is_powerful_vassal_of = $FACTION_TARGET$
			save_temporary_opinion_value_as = { name = opinion_of_current_liege target = $FACTION_TARGET$ }
			opinion = { target = $FACTION_CLAIMANT$ value > scope:opinion_of_current_liege }
		}
		who = root
		opinion_target = $FACTION_TARGET$
		multiplier = -1.5
		min = 0
	}

	# They do not like the claimant more than their liege, unless its a claimant of their own culture
	modifier = {
		desc = "FACTION_REASON_LIKES_LIEGE_UNLESS_CULTURE"
		add = -50
		NOT = {	$FACTION_CLAIMANT$ = root }
		NAND = {
			culture = $FACTION_CLAIMANT$.culture
			NOT = { culture = $FACTION_TARGET$.culture }
		}
		save_temporary_opinion_value_as = { name = opinion_of_current_liege target = $FACTION_TARGET$ }
		opinion = { target = $FACTION_CLAIMANT$ value < scope:opinion_of_current_liege }
	}

	modifier = { # If you like the Claimant better than your liege, increase the score
		desc = "FACTION_REASON_LIKE_CLAIMANT_MORE_THAN_LIEGE"
		NOT = {	$FACTION_CLAIMANT$ = root }
		save_temporary_opinion_value_as = { name = opinion_of_current_liege target = $FACTION_TARGET$ }
		save_temporary_opinion_value_as = { name = opinion_of_claimant target = $FACTION_CLAIMANT$ }
		scope:opinion_of_claimant > liege_opinion_value
		scope:opinion_of_claimant > 0
		add = {
			value = scope:opinion_of_claimant
			multiply = 1.5
			subtract = scope:opinion_of_current_liege
		}
	}

	opinion_modifier = { # Reduce likelihood of joining if you have positive opinion of your liege
		desc = "FACTION_REASON_LIKES_LIEGE"
		who = root
		opinion_target = $FACTION_TARGET$
		multiplier = -0.5
		max = 0
	}

	modifier = {
		desc = "FACTION_REASON_CLAIMANT_TOO_OLD"
		add = { # Claimant is too old
			value = $FACTION_CLAIMANT$.age
			subtract = 45
			multiply = -4
		}
		NOT = {	$FACTION_CLAIMANT$ = root }
		$FACTION_CLAIMANT$.age > 45
	}
	modifier = { # Claimant is too young
		desc = "FACTION_REASON_CLAIMANT_TOO_YOUNG"
		add = -25
		NOT = { $FACTION_CLAIMANT$ = root }
		$FACTION_CLAIMANT$ = { is_adult = no }
	}
	modifier = {
		desc = "FACTION_REASON_CLAIMAINT_DYING"
		add = { # Claimant is dying
			value = 1.5
			subtract = $FACTION_CLAIMANT$.health
			multiply = -20
		}
		NOT = {	$FACTION_CLAIMANT$ = root }
		$FACTION_CLAIMANT$.health < 1.5
	}
	modifier = {
		desc = "FACTION_REASON_CLAIMANT_RARE_PRODUCE_HEIR"
		add = -50
		# Claimant does not have children and is unlikely to have any.
		$FACTION_CLAIMANT$.fertility <= 0.1
		NOT = {	$FACTION_CLAIMANT$ = root }
		NOT = {
			$FACTION_CLAIMANT$ = {
				any_child = { count >= 1 }
			}
		}
	}

	# Infirmity of claimant
	modifier = {
		desc = "FACTION_REASON_INFIRM"
		add = -50
		NOT = { $FACTION_CLAIMANT$ = root }
		$FACTION_CLAIMANT$ = { has_trait = infirm }
	}

	# Claimant has low Legitimacy
	modifier = {
		desc = "FACTION_REASON_CLAIMANT_LOW_LEGITIMACY"
		add = -100
		$FACTION_CLAIMANT$ = {
			has_legitimacy = yes
			legitimacy_level = 0
		}
	}

	# Claimant has low Legitimacy
	modifier = {
		desc = "FACTION_REASON_CLAIMANT_LOW_LEGITIMACY"
		add = -50
		$FACTION_CLAIMANT$ = {
			has_legitimacy = yes
			legitimacy_level = 1
		}
	}

	# Claimant has low Legitimacy
	modifier = {
		desc = "FACTION_REASON_CLAIMANT_LOW_LEGITIMACY"
		add = -25
		$FACTION_CLAIMANT$ = {
			has_legitimacy = yes
			legitimacy_level = 2
		}
	}

	# I am the claimant!
	modifier = {
		desc = "FACTION_REASON_MEMBER_IS_CLAIMANT"
		add = {
			value = 50 # Basic 'self-love' bonus
			add = {
				value = ai_greed
				multiply = 1.5
				min = 0
			}
		}
		AND = {
			$FACTION_CLAIMANT$ = root
			NOT = { has_trait = content } # Not opposed to acquiring more power/wealth
		}
	}

	# Legacy
	modifier = {
		desc = "FACTION_REASON_GLORY_LEGACY_4"
		add = -20
		$FACTION_TARGET$.dynasty ?= { has_dynasty_perk = glory_legacy_4 }
	}

	# Friends & Lovers don't want to join
	modifier = {
		desc = "FACTION_REASON_TARGET_FRIEND_LOVER"
		add = -500
		OR = {
			has_secret_relation_lover = $FACTION_TARGET$
			has_relation_lover = $FACTION_TARGET$
			has_relation_soulmate = $FACTION_TARGET$
			has_relation_friend = $FACTION_TARGET$
			has_relation_best_friend = $FACTION_TARGET$
		}
	}
	# Friends & Lovers want to support their claimants!
	modifier = {
		desc = "FACTION_REASON_CLAIMANT_FRIEND_LOVER"
		add = 25
		OR = {
			has_secret_relation_lover = $FACTION_CLAIMANT$
			has_relation_lover = $FACTION_CLAIMANT$
			has_relation_soulmate = $FACTION_CLAIMANT$
			has_relation_friend = $FACTION_CLAIMANT$
			has_relation_best_friend = $FACTION_CLAIMANT$
		}
	}
	# Best Friends & Soulmates really want to support their claimants!
	modifier = {
		desc = "FACTION_REASON_CLAIMANT_SUPER_FRIEND_LOVER"
		add = 100
		OR = {
			has_relation_soulmate = $FACTION_CLAIMANT$
			has_relation_best_friend = $FACTION_CLAIMANT$
		}
	}

	# Dynasty
	modifier = {
		NOT = { this = $FACTION_CLAIMANT$ }
		exists = house
		exists = $FACTION_CLAIMANT$.house
		house != $FACTION_CLAIMANT$.house
		dynasty = $FACTION_CLAIMANT$.dynasty
		dynasty != $FACTION_TARGET$.dynasty
		add = 5
		desc = FACTION_REASON_CLAIMANT_DYNASTY
	}
	# House
	modifier = {
		NOT = { this = $FACTION_CLAIMANT$ }
		exists = house
		exists = $FACTION_CLAIMANT$.house
		house = $FACTION_CLAIMANT$.house
		house != $FACTION_TARGET$.house
		add = 10
		desc = FACTION_REASON_CLAIMANT_HOUSE
	}
	# Parent
	modifier = {
		NOT = { this = $FACTION_CLAIMANT$ }
		is_parent_of = $FACTION_CLAIMANT$
		NOT = { is_parent_of = $FACTION_TARGET$ }
		desc = FACTION_REASON_CLAIMANT_PARENT
		add = 30
	}
	# Close family
	modifier = {
		NOT = { this = $FACTION_CLAIMANT$ }
		is_close_family_of = $FACTION_CLAIMANT$
		NOT = { is_parent_of = $FACTION_CLAIMANT$ }
		NOT = { is_close_family_of = $FACTION_TARGET$ }
		add = 20
		desc = FACTION_REASON_CLAIMANT_CLOSE_FAMILY
	}
	# Extended family
	modifier = {
		NOT = { this = $FACTION_CLAIMANT$ }
		is_extended_family_of = $FACTION_CLAIMANT$
		NOT = { is_extended_family_of = $FACTION_TARGET$ }
		add = 10 
		desc = FACTION_REASON_CLAIMANT_EXTENDED_FAMILY
	}
	# Heir
	modifier = {
		primary_title = {
			place_in_line_of_succession = {
				target = $FACTION_CLAIMANT$
				value <= 5
			}
		}
		$FACTION_CLAIMANT$ = {
			OR = {
				is_child_of = root
				is_sibling_of = root
				is_nibling_of = root
			}
			save_temporary_scope_as = faction_claimant_temp
		}
		add = {
			value = 25
			multiply = {
				value = 5
				subtract = "primary_title.place_in_line_of_succession(scope:faction_claimant_temp)"
			}
			if = {
				limit = { primary_heir ?= $FACTION_CLAIMANT$ }
				add = 25
			}
		}
		desc = FACTION_REASON_CLAIMANT_PRIMARY_HEIR
	}

	# Liege is too young to rule
	modifier = {
		desc = "FACTION_REASON_TARGET_IS_CHILD"
		add = 25
		$FACTION_TARGET$ = { is_adult = no }
	}

	# Cultural reasons
	modifier = {
		desc = "FACTION_REASON_CULTURAL_REASONS"
		culture = {
			NOR = {
				this = $FACTION_TARGET$.culture
				cultural_acceptance = { target = $FACTION_TARGET$.culture value >= 90 } # Essentially the same culture
				has_cultural_parameter = doesnt_care_about_culture_faith_in_factions
			}
			OR = {
				this = $FACTION_CLAIMANT$.culture
				cultural_acceptance = { target = $FACTION_CLAIMANT$.culture value >= 90 } # Essentially the same culture
			}
		}
		add = {
			value = 50
			culture = {
				if = {
					limit = { this = $FACTION_CLAIMANT$.culture }
					add = 50
				}
				if = {
					limit = {
						cultural_acceptance = { target = $FACTION_TARGET$.culture value <= 20 }
					}
					add = 25
				}
				if = {
					limit = {
						cultural_acceptance = { target = $FACTION_TARGET$.culture value <= 35 }
					}
					add = 15
				}
				if = {
					limit = {
						cultural_acceptance = { target = $FACTION_TARGET$.culture value <= 50 }
					}
					add = 10
				}
				if = {
					limit = {
						cultural_acceptance = { target = $FACTION_TARGET$.culture value <= 70 }
					}
					add = 5
				}
				if = {
					limit = {
						cultural_acceptance = { target = $FACTION_TARGET$.culture value <= 80 }
					}
					add = 5
				}
			}
			if = { # The liege knowing your language cuts this penalty in half
				limit = {
					$FACTION_TARGET$ = { knows_language_of_culture = prev.culture }
				}
				multiply = 0.5
			}
			if = { # Cultural reasons matter less in the HRE
				limit = {
					$FACTION_TITLE$ = { has_title_law = princely_elective_succession_law }
				}
				multiply = 0.25
			}
		}
	}

	# Faith
	modifier = {
		desc = "FACTION_REASON_CLAIMAINT_SAME_FAITH"
		add = 100
		NOT = { faith = $FACTION_TARGET$.faith }
		faith = $FACTION_CLAIMANT$.faith
		NOT = {
			culture = { has_cultural_parameter = doesnt_care_about_culture_faith_in_factions }
		}
	}

	modifier = {
		desc = "FACTION_REASON_CLAIMANT_FAITH_ASTRAY"
		add = -25
		NOT = { faith = $FACTION_CLAIMANT$.faith }
		faith = {
			faith_hostility_level = {
				target = $FACTION_CLAIMANT$.faith
				value = faith_astray_level
			}
		}
		NOT = {
			culture = { has_cultural_parameter = doesnt_care_about_culture_faith_in_factions }
		}
	}

	modifier = {
		desc = "FACTION_REASON_CLAIMANT_FAITH_HOSTILE"
		add = -250
		NOT = { faith = $FACTION_CLAIMANT$.faith }
		faith = {
			faith_hostility_level = {
				target = $FACTION_CLAIMANT$.faith
				value = faith_hostile_level
			}
		}
		NOT = {
			culture = { has_cultural_parameter = doesnt_care_about_culture_faith_in_factions }
		}
	}

	modifier = {
		desc = "FACTION_REASON_CLAIMANT_FAITH_EVIL"
		add = -1000
		NOT = { faith = $FACTION_CLAIMANT$.faith }
		faith = {
			faith_hostility_level = {
				target = $FACTION_CLAIMANT$.faith
				value = faith_evil_level
			}
		}
		NOT = {
			culture = { has_cultural_parameter = doesnt_care_about_culture_faith_in_factions }
		}
	}

	# Don't support claims against the liege's lower tier titles
	modifier = {
		desc = "FACTION_REASON_LOW_TIER_TARGET_TITLE"
		add = -500
		$FACTION_TITLE$.tier < $FACTION_TARGET$.primary_title.tier
		$FACTION_TITLE$.tier < tier_kingdom
	}

	# If I'm de jure of the Claimant, I want to support them
	modifier = {
		desc = "FACTION_REASON_CLAIMANT_IS_RIGHTFUL_LIEGE"
		add = 100
		$FACTION_CLAIMANT$ = { is_rightful_liege_of = root }
	}

	# When creating a Faction, primarily care about Claims on Titles de jure above my primary title
	modifier = {
		desc = "FACTION_REASON_TITLE_DEJURE_ABOVE"
		add = -100
		root.primary_title = { is_noble_family_title = no }
		NOT = {
			$FACTION_TITLE$ = { is_de_jure_liege_or_above_target = root.primary_title }
		}
	}

	# If I'm not a de jure vassal of my liege, and my liege is independent, prefer to create an independence faction
	modifier = {
		desc = "FACTION_REASON_PREFER_INDEPENDENCE_FACTION"
		add = -200
		liege = { is_independent_ruler = yes }
		NOT = { government_allows = administrative }
		NOT = {
			$FACTION_TARGET$ = { is_rightful_liege_of = root }
		}
	}

	# If liege is Unpreferred heir, nudge towards claimant factions
	modifier = {
		desc = "FACTION_REASON_LIEGE_IS_UNPREFERRED_HEIR"
		add = 25
		NOT = { was_preferred_heir = $FACTION_TARGET$ }
	}

	# If liege is Preferred heir, nudge away from claimant factions
	modifier = {
		desc = "FACTION_REASON_LIEGE_IS_PREFERRED_HEIR"
		add = -25
		was_preferred_heir = $FACTION_TARGET$
	}

	# All else being equal, the AI might support a claimant over their current liege just to get better feudal obligations.
	modifier = {
		desc = "FACTION_REASON_BETTER_CROWN_AUTHORITY"
		add = 10
		AND = {
			$FACTION_TARGET$ = { has_realm_law = crown_authority_1 }
			$FACTION_CLAIMANT$ = { has_realm_law = crown_authority_0 }
		}
	}
	modifier = {
		desc = "FACTION_REASON_BETTER_CROWN_AUTHORITY"
		add = 15
		AND = {
			$FACTION_TARGET$ = { has_realm_law = crown_authority_2 }
			$FACTION_CLAIMANT$ = {
				OR = {
					has_realm_law = crown_authority_0
					has_realm_law = crown_authority_1
				}
			}
		}
	}
	modifier = {
		desc = "FACTION_REASON_BETTER_CROWN_AUTHORITY"
		add = 15
		AND = {
			$FACTION_TARGET$ = { has_realm_law = crown_authority_3 }
			$FACTION_CLAIMANT$ = {
				OR = {
					has_realm_law = crown_authority_0
					has_realm_law = crown_authority_1
					has_realm_law = crown_authority_2
				}
			}
		}
	}

	# More likely to create a claimant faction against a Ruler below their CGLevel
	modifier = {
		desc = "FACTION_REASON_LOWER_COURT_GRANDEUR"
		add = 50
		$FACTION_TARGET$.court_grandeur_current_level < $FACTION_TARGET$.court_grandeur_minimum_expected_level
	}

	# Unity - House members are more likely to join and create claimant factions with low levels of unity
	modifier = { # Competitive unity level
		add = 20
		desc = "FACTION_REASON_unity_more_likely_claimant_factions"
		exists = root.house
		exists = $FACTION_TARGET$.house
		house = $FACTION_TARGET$.house
		house = { has_house_unity_parameter = unity_more_likely_claimant_factions }
	}
	modifier = { # Antagonistic unity level
		add = 40
		desc = "FACTION_REASON_unity_significantly_more_likely_claimant_factions"
		exists = root.house
		exists = $FACTION_TARGET$.house
		house = $FACTION_TARGET$.house
		house = { has_house_unity_parameter = unity_significantly_more_likely_claimant_factions }
	}

	modifier = {
		desc = "FACTION_REASON_PERSIAN_STRUGGLE"
		factor = 1.2
		any_character_struggle = { is_struggle_type = persian_struggle }
	}

	# LOW LEGITIMACY
	modifier = {
		desc = "FACTION_REASON_LOW_LEGITIMACY"
		$FACTION_TARGET$ = {
			OR = {
				has_legitimacy_flag = increased_factions
				has_legitimacy_flag = very_increased_factions
				has_legitimacy_flag = massively_increased_factions
			}
		}
		add = {
			value = 10
			$FACTION_TARGET$ = {
				if = {
					limit = { has_legitimacy_flag = very_increased_factions }
					add = 10
				}
				else_if = {
					limit = { has_legitimacy_flag = massively_increased_factions }
					add = 20
				}
			}
		}
	}

	# HIGH LEGITIMACY
	modifier = {
		desc = "FACTION_REASON_HIGH_LEGITIMACY"
		$FACTION_TARGET$ = {
			OR = {
				has_legitimacy_flag = reduced_factions
				has_legitimacy_flag = very_reduced_factions
				has_legitimacy_flag = extra_reduced_factions
			}
		}
		add = {
			value = -10
			$FACTION_TARGET$ = {
				if = {
					limit = { has_legitimacy_flag = very_reduced_factions }
					add = -10
				}
				else_if = {
					limit = { has_legitimacy_flag = extra_reduced_factions }
					add = -20
				}
			}
		}
	}

	### HARRYING OF THE NORTH
	# Increases Claimant faction likelihood if Resistance is high
	modifier = {
		desc = "FACTION_REASON_HARRYING_RESISTANCE"
		$FACTION_TARGET$ = {
			AND = {
				any_owned_story = {
					story_type = story_cycle_harrying_of_the_north
					var:resistance > 7
					var:resistance > var:pacification
				}
			}
		}
		add = {
			value = 0
			if = {
				limit = { 
					$FACTION_TARGET$ = { 
						any_owned_story = {
							story_type = story_cycle_harrying_of_the_north
							var:resistance > 7
						}
					} 
				}
				add = 15
			}
			else_if = {
				limit = { 
					$FACTION_TARGET$ = { 
						any_owned_story = {
							story_type = story_cycle_harrying_of_the_north
							var:resistance > 10
						}
					} 
				}
				add = 30
			}
			else_if = {
				limit = { 
					$FACTION_TARGET$ = { 
						any_owned_story = {
							story_type = story_cycle_harrying_of_the_north
							var:resistance > 13
						}
					} 
				}
				add = 50
			}
			else_if = {
				limit = { 
					$FACTION_TARGET$ = { 
						any_owned_story = {
							story_type = story_cycle_harrying_of_the_north
							var:resistance > 16
						}
					} 
				}
				add = 80
			}
		}
	}

	# Decreases Claimant faction likelihood if Pacification is high
	# This has lower thresholds but also lower rewards
	modifier = {
		desc = "FACTION_REASON_HARRYING_PACIFICATION"
		$FACTION_TARGET$ = {
			AND = {
				any_owned_story = {
					story_type = story_cycle_harrying_of_the_north
					var:pacification > 5
					var:pacification > var:resistance
				}
			}
		}
		add = {
			value = 0
			if = {
				limit = { 
					$FACTION_TARGET$ = { 
						any_owned_story = {
							story_type = story_cycle_harrying_of_the_north
							var:pacification > 5
						}
					} 
				}
				add = -5
			}
			else_if = {
				limit = { 
					$FACTION_TARGET$ = { 
						any_owned_story = {
							story_type = story_cycle_harrying_of_the_north
							var:pacification > 8
						}
					} 
				}
				add = -10
			}
			else_if = {
				limit = { 
					$FACTION_TARGET$ = { 
						any_owned_story = {
							story_type = story_cycle_harrying_of_the_north
							var:pacification > 11
						}
					} 
				}
				add = -15
			}
			else_if = {
				limit = { 
					$FACTION_TARGET$ = { 
						any_owned_story = {
							story_type = story_cycle_harrying_of_the_north
							var:pacification > 14
						}
					} 
				}
				add = -20
			}
		}
	}

	# Finally, multiplicative modifier for if they're Anglo-Saxon and you're Norman
	modifier = {
		desc = "FACTION_REASON_HARRYING_ANGLO_SAXON"
		$FACTION_TARGET$ = {
			AND = {
				any_owned_story = {
					story_type = story_cycle_harrying_of_the_north
				}
				culture = culture:norman
			}
		}
		$FACTION_CLAIMANT$ = {
			culture = culture:anglo_saxon
		}
		factor = 1.5
	}

	# Nomads choose a claimant per chaotic kurultai succession that they want, otherwise they go for other factions
	modifier = {
		desc = "FACTION_REASON_NOMADIC"
		add = -3000
		government_has_flag = government_is_nomadic
		$FACTION_CLAIMANT$ = {
			NOT = {
				has_character_flag = nomad_preferred_claimant
			}
		}
	}

	# If another Claimant Faction already exists, prefer to side with it
	modifier = {
		desc = "FACTION_REASON_SIDE_WITH_EXISTING"
		add = {
			value = -100
			if = {
				limit = {
					government_has_flag = government_is_nomadic
				}
				add = -2900
			}
		}
		trigger_if = {
			limit = {
				exists = joined_faction
			}
			joined_faction = { save_temporary_scope_as = joined_faction_temp }
		}
		$FACTION_TARGET$ = {
			any_targeting_faction = {
				trigger_if = {
					limit = {
						exists = scope:joined_faction_temp
					}
					NOT = { this = scope:joined_faction_temp }
				}
				# Exists another claimant faction
		  		faction_is_type = claimant_faction
		  		# No player in that faction
			  	NOT = {
		  			any_faction_member = { is_ai = no }
		  		}
		  		# Faction claimant is one of following:
		  		# 1. my soulmate
		  		# 2. my best-friend
		  		# 3. my primary heir, who I like, and is my child, sibling, or nibling
		  		# 4. my opinion of them is higher than liege + higher than current faction claimant + their faith matches mine/is also pluralistic + their culture matches mine or is highly accepted
				special_character = {
					OR = {
						has_relation_soulmate = root
						has_relation_best_friend = root
						AND = {
							root.primary_heir ?= this
							reverse_opinion = { target = root value >= medium_positive_opinion }
							OR = {
								is_child_of = root
								is_sibling_of = root
								is_nibling_of = root
							}
						}
						AND = {
							root = {
								save_temporary_opinion_value_as = { name = opinion_of_current_liege target = $FACTION_TARGET$ }
								opinion = { target = prev value > scope:opinion_of_current_liege }
							}
							trigger_if = {
								limit = { exists = scope:joined_faction_temp.special_character }
								root = {
									save_temporary_opinion_value_as = { name = opinion_of_current_faction_claimant target = scope:joined_faction_temp.special_character }
									opinion = { target = prev value > scope:opinion_of_current_faction_claimant }
								}
							}
							OR = {
								AND = {
									root.faith = { has_doctrine = doctrine_pluralism_pluralistic }
									faith = { has_doctrine = doctrine_pluralism_pluralistic }
								}
								faith = root.faith
							}
							culture = {
								OR = {
									this = root.culture
									cultural_acceptance = { target = root.culture value >= 90 } # Essentially the same culture
								}
							}
						}
						AND = { # Nomads tend to clump up against bad khans
							government_has_flag = government_is_nomadic
							$FACTION_TARGET$ = {
								government_has_flag = government_is_nomadic
							}
							root = {
								government_has_flag = government_is_nomadic
							}
						}
					}
				}
	  		}
	  	}
	}

	# EP3 Dynasty Legacy Perk Malus
	modifier = {
		add = -50
		$FACTION_TARGET$.dynasty ?= { has_dynasty_perk = ep3_administrative_legacy_5 }
	}
}

struggle_faction_modifiers = {
	# Struggle Modifiers.
	## Weight up in general sometimes.
	modifier = {
		desc = FACTION_FP3_STRUGGLE_FRICTION
		has_trait = fp3_struggle_detractor
		scope:faction = {
			# Don't weight up dissolution factions unduly.
			NOT = { faction_is_type = nation_fracturing_faction }
			# Targeting the caliph uses different logic.
			faction_target = { fp3_struggle_scoped_is_the_arabian_caliph_trigger = no }
		}
		add = {
			value = 25
			# Weight up independence factions a little more.
			if = {
				limit = {
					scope:faction = { faction_is_type = independence_faction }
				}
				add = 25
			}
		}
	}
	## Weight up further against specific targets.
	modifier = {
		desc = FACTION_FP3_STRUGGLE_FRICTION_CALIPHAL
		has_trait = fp3_struggle_detractor
		scope:faction = {
			# Don't weight up dissolution factions unduly.
			NOT = { faction_is_type = nation_fracturing_faction }
			# Targeting the caliph uses different logic.
			faction_target = { fp3_struggle_scoped_is_the_arabian_caliph_trigger = yes }
		}
		add = {
			value = 35
			# Weight up independence factions a little more.
			if = {
				limit = {
					scope:faction = { faction_is_type = independence_faction }
				}
				add = 35
			}
		}
	}
}

join_faction_stacking_modifiers = {
	##########################
	# Faction 'Stacking' Factors, attempts to cluster AI rulers into several powerful factions instead of many weak ones.
	modifier = {
		desc = "FACTION_REASON_POWER_MINIMAL"
		scope:faction.faction_power < scope:faction.faction_power_minimal
		liege = {
			any_targeting_faction = {
				faction_is_type = independence_faction
				faction_power >= faction_power_minimal
			}
		}
		factor = faction_weight_factor_power_minimal_penalty
	}
	modifier = {
		desc = "FACTION_REASON_POWER_HALFWAY_THRESHOLD"
		scope:faction.faction_power >= scope:faction.faction_power_halfway_threshold
		scope:faction.faction_power < scope:faction.faction_power_pushing_threshold
		factor = faction_weight_factor_power_halfway_threshold
	}
	modifier = {
		desc = "FACTION_REASON_POWER_PUSHING_THRESHOLD"
		scope:faction.faction_power >= scope:faction.faction_power_pushing_threshold
		scope:faction.faction_power < scope:faction.faction_power_threshold
		factor = faction_weight_factor_power_pushing_threshold
	}
	modifier = {
		desc = "FACTION_REASON_POWER_THRESHOLD"
		scope:faction.faction_power >= scope:faction.faction_power_threshold
		factor = faction_weight_factor_power_exceeds_threshold
	}
}

# Modifiers specific to Admin realms
admin_faction_modifiers = {
	# Reign duration
	modifier = { # Encourage factions during short reigns
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		$FACTION_TARGET$.primary_title.title_held_years > 5
		add = {
			subtract = $FACTION_TARGET$.primary_title.title_held_years
			add = 5
			multiply = 5
		}
		desc = FACTION_REASON_ADMIN_SHORT_REIGN_REASON
	}
	# Discourage factions of the same type as an existing much stronger faction
	modifier = {
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		exists = joined_faction
		joined_faction = { save_temporary_scope_as = joined_faction_temp }
		$FACTION_TARGET$ = {
			any_targeting_faction = {
				NOT = { this = scope:joined_faction_temp }
				faction_is_type = $FACTION_TYPE$
				faction_power > scope:joined_faction_temp.faction_power_existing_threshold_value
			}
		}
		factor = -0.5
		desc = FACTION_REASON_ADMIN_EXISTING_STRONGER_FACTION_OF_SAME_TYPE_REASON
	}
	# Poor Liege Skill
	modifier = {
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		$FACTION_TARGET$.sum_of_all_skills_and_prowess_value < 30
		add = {
			value = 30
			subtract = $FACTION_TARGET$.sum_of_all_skills_and_prowess_value
			min = 0
			multiply = 2
		}
		desc = FACTION_REASON_ADMIN_LIEGE_POOR_SKILL
	}
	# Negative Traits
	modifier = { # Criminal Liege's are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOR = {
			has_trait = deviant
			any_secret = { secret_type = secret_deviant }
		}
		$FACTION_TARGET$ = {
			has_trait = deviant
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = $FACTION_TARGET$.primary_title.state_faith GENDER_CHARACTER = $FACTION_TARGET$ }
		}
		add = 20
		desc = FACTION_REASON_ADMIN_LIEGE_DEVIANT_AND_CRIMINAL
	}
	modifier = { # Criminal Liege's are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOR = {
			has_trait = incestuous
			any_secret = { secret_type = secret_incest }
		}
		$FACTION_TARGET$ = {
			has_trait = incestuous
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = incestuous FAITH = $FACTION_TARGET$.primary_title.state_faith GENDER_CHARACTER = $FACTION_TARGET$ }
		}
		add = 20
		desc = FACTION_REASON_ADMIN_LIEGE_INCESTUOUS_AND_CRIMINAL
	}
	modifier = { # Criminal Liege's are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOR = {
			has_trait = sodomite
			any_secret = { secret_type = secret_homosexual }
		}
		$FACTION_TARGET$ = {
			has_trait = sodomite
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = sodomite FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = 20
		desc = FACTION_REASON_ADMIN_LIEGE_SODOMITE_AND_CRIMINAL
	}
	modifier = { # Criminal Liege's are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOR = {
			has_trait = cannibal
			any_secret = { secret_type = secret_cannibal }
		}
		$FACTION_TARGET$ = {
			has_trait = cannibal
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = cannibal FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = 20
		desc = FACTION_REASON_ADMIN_LIEGE_CANNIBAL_AND_CRIMINAL
	}
	modifier = { # Criminal Liege's are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOT = { has_trait = kinslayer }
		$FACTION_TARGET$ = {
			has_trait = kinslayer_1
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = kinslayer_1 FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = 20
		desc = FACTION_REASON_ADMIN_LIEGE_KINSLAYER_1_AND_CRIMINAL
	}
	modifier = { # Criminal Liege's are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOT = { has_trait = kinslayer }
		$FACTION_TARGET$ = {
			has_trait = kinslayer_2
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = kinslayer_2 FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = 30
		desc = FACTION_REASON_ADMIN_LIEGE_KINSLAYER_2_AND_CRIMINAL
	}
	modifier = { # Criminal Liege's are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOT = { has_trait = kinslayer }
		$FACTION_TARGET$ = {
			has_trait = kinslayer_3
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = kinslayer_3 FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = 40
		desc = FACTION_REASON_ADMIN_LIEGE_KINSLAYER_3_AND_CRIMINAL
	}
	modifier = { # Criminal Liege's are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOR = {
			has_trait = witch
			any_secret = { secret_type = secret_witch }
		}
		$FACTION_TARGET$ = {
			has_trait = witch
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = witch FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = 20
		desc = FACTION_REASON_ADMIN_LIEGE_WITCH_AND_CRIMINAL
	}
	modifier = { # Criminal Liege's are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOR = {
			has_trait = adulterer
			any_secret = { secret_type = secret_lover }
		}
		$FACTION_TARGET$ = {
			has_trait = adulterer
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = adulterer FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = 20
		desc = FACTION_REASON_ADMIN_LIEGE_ADULTERER_AND_CRIMINAL
	}
	modifier = { # Criminal Liege's are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOT = { has_trait = fornicator }
		$FACTION_TARGET$ = {
			has_trait = fornicator
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = fornicator FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = 20
		desc = FACTION_REASON_ADMIN_LIEGE_FORNICATOR_AND_CRIMINAL
	}
}

# Modifiers specific to claimant factions in Admin realms
admin_claimant_faction_modifiers = {
	# State Faith
	modifier = { # State Faith is preferred if Liege does not follow it
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOT = { faith = $FACTION_TARGET$.faith }
		faith = $FACTION_CLAIMANT$.faith
		$FACTION_TARGET$.primary_title.state_faith ?= faith
		add = 75
		desc = FACTION_REASON_ADMIN_CLAIMANT_STATE_FAITH
	}
	modifier = { # Don't push a claimaint who doesn't follow the State Faith, especially when a zealot
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		$FACTION_TARGET$.primary_title.state_faith ?= faith
		$FACTION_CLAIMANT$.faith != faith
		add = {
			value = -40
			if = {
				limit = { has_vassal_stance = zealot }
				multiply = 2
			}
		}
		desc = FACTION_REASON_ADMIN_CLAIMANT_NOT_STATE_FAITH
	}
	# Stances
	modifier = { # Courtly want diplomatic Lieges
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOT = { this = $FACTION_CLAIMANT$ }
		has_vassal_stance = courtly
		add = {
			value = $FACTION_CLAIMANT$.diplomacy
			subtract = $FACTION_TARGET$.diplomacy
			multiply = 5
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = gregarious }
					NOT = { $FACTION_TARGET$ = { has_trait = gregarious } }
				}
				add = 10
			}
			else_if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = shy }
					NOT = { $FACTION_TARGET$ = { has_trait = shy } }
				}
				add = -10
			}
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = august }
					NOT = { $FACTION_TARGET$ = { has_trait = august } }
				}
				add = 10
			}
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = family_first }
					NOT = { $FACTION_TARGET$ = { has_trait = family_first } }
				}
				add = 10
			}
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = diplomat }
					NOT = { $FACTION_TARGET$ = { has_trait = diplomat } }
				}
				add = 10
			}
		}
		desc = FACTION_REASON_ADMIN_COURTLY
	}
	modifier = { # Glory Hounds want martial Lieges
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOT = { this = $FACTION_CLAIMANT$ }
		has_vassal_stance = glory_hound
		add = {
			value = $FACTION_CLAIMANT$.martial
			subtract = $FACTION_TARGET$.martial
			multiply = 5
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = brave }
					NOT = { $FACTION_TARGET$ = { has_trait = brave } }
				}
				add = 10
			}
			else_if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = craven }
					NOT = { $FACTION_TARGET$ = { has_trait = craven } }
				}
				add = -10
			}
			add = {
				value = $FACTION_CLAIMANT$.number_of_commander_traits
				subtract = $FACTION_TARGET$.number_of_commander_traits
				multiply = 5
			}
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = gallant }
					NOT = { $FACTION_TARGET$ = { has_trait = gallant } }
				}
				add = 10
			}
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = overseer }
					NOT = { $FACTION_TARGET$ = { has_trait = overseer } }
				}
				add = 10
			}
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = strategist }
					NOT = { $FACTION_TARGET$ = { has_trait = strategist } }
				}
				add = 10
			}
		}
		desc = FACTION_REASON_ADMIN_GLORY_HOUND
	}
	modifier = { # Parochial want stewardly Lieges
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOT = { this = $FACTION_CLAIMANT$ }
		has_vassal_stance = parochial
		add = {
			value = $FACTION_CLAIMANT$.stewardship
			subtract = $FACTION_TARGET$.stewardship
			multiply = 5
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = zealous }
					NOT = { $FACTION_TARGET$ = { has_trait = zealous } }
				}
				add = 10
			}
			else_if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = cynical }
					NOT = { $FACTION_TARGET$ = { has_trait = cynical } }
				}
				add = -10
			}
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = architect }
					NOT = { $FACTION_TARGET$ = { has_trait = architect } }
				}
				add = 10
			}
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = administrator }
					NOT = { $FACTION_TARGET$ = { has_trait = administrator } }
				}
				add = 10
			}
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = avaricious }
					NOT = { $FACTION_TARGET$ = { has_trait = avaricious } }
				}
				add = 10
			}
		}
		desc = FACTION_REASON_ADMIN_PAROCHIAL
	}
	modifier = { # Zealots want learned Lieges
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOT = { this = $FACTION_CLAIMANT$ }
		has_vassal_stance = zealot
		faith = $FACTION_CLAIMANT$.faith
		faith = $FACTION_TARGET$.faith # Dislike of other faiths handled already
		add = {
			value = $FACTION_CLAIMANT$.learning
			subtract = $FACTION_TARGET$.learning
			multiply = 2
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = diligent }
					NOT = { $FACTION_TARGET$ = { has_trait = diligent } }
				}
				add = 10
			}
			else_if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = lazy }
					NOT = { $FACTION_TARGET$ = { has_trait = lazy } }
				}
				add = -10
			}
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = whole_of_body }
					NOT = { $FACTION_TARGET$ = { has_trait = whole_of_body } }
				}
				add = 10
			}
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = scholar }
					NOT = { $FACTION_TARGET$ = { has_trait = scholar } }
				}
				add = 10
			}
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = theologian }
					NOT = { $FACTION_TARGET$ = { has_trait = theologian } }
				}
				add = 10
			}
		}
		desc = FACTION_REASON_ADMIN_ZEALOT
	}
	modifier = { # Minorities want representative Lieges
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOT = { this = $FACTION_CLAIMANT$ }
		has_vassal_stance = minority
		OR = {
			AND = {
				culture != $FACTION_TARGET$.culture
				culture = $FACTION_CLAIMANT$.culture
			}
			AND = {
				faith != $FACTION_TARGET$.faith
				faith = $FACTION_CLAIMANT$.faith
			}
		}
		add = {
			value = 10
			if = {
				limit = {
					culture = $FACTION_CLAIMANT$.culture
					faith = $FACTION_CLAIMANT$.faith
				}
				add = 10
			}
			if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = just }
					NOT = { $FACTION_TARGET$ = { has_trait = just } }
				}
				add = 10
			}
			else_if = {
				limit = {
					$FACTION_CLAIMANT$ = { has_trait = arbitrary }
					NOT = { $FACTION_TARGET$ = { has_trait = arbitrary } }
				}
				add = -10
			}
		}
		desc = FACTION_REASON_ADMIN_MINORITY
	}
	# Skill Relative
	modifier = { # Directly compare the governor efficiency of liege to claimant
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		NOT = { this = $FACTION_CLAIMANT$ }
		add = {
			value = $FACTION_CLAIMANT$.governor_efficiency
			subtract = $FACTION_TARGET$.governor_efficiency
			multiply = 200 # Let's make sure this has a fairly high impact
		}
		desc = FACTION_REASON_ADMIN_RELATIVE_SKILL
	}
	# Family Reasons
	modifier = { # Don't support a claimant who doesn't belong to a powerful family (unless same house as claimant)
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		exists = $FACTION_CLAIMANT$.house
		NOT = { house ?= $FACTION_CLAIMANT$.house }
		$FACTION_CLAIMANT$.house = { is_powerful_family = no }
		add = -30
		desc = FACTION_REASON_ADMIN_POWERFUL_FAMILY # Needs better loc
	}
	modifier = { # Dominant Family members are preferred Claimants
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		exists = $FACTION_CLAIMANT$.house
		$FACTION_CLAIMANT$.house = { is_dominant_family = yes }
		add = 20
		desc = FACTION_REASON_ADMIN_DOMINANT_FAMILY
	}
	modifier = { # Less likely to support other houses when their own house is powerful/dominant
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		exists = $FACTION_CLAIMANT$.house
		house ?= {
			OR = {
				is_powerful_family = yes
				is_dominant_family = yes
			}
			NOT = { this = $FACTION_CLAIMANT$.house }
		}
		add = -20
		desc = MY_HOUSE_IS_POWERFUL # Needs better loc
	}
	modifier = { # Less likely to support other houses when their own house is on the throne
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		exists = $FACTION_CLAIMANT$.house
		exists = $FACTION_TARGET$.house
		house ?= {
			NOT = { this = $FACTION_CLAIMANT$.house }
			this = $FACTION_TARGET$.house
		}
		add = -20
		desc = FACTION_REASON_CLAIMANT_HOUSE # Needs better loc
	}
	# Negative Traits
	modifier = { # Criminal Claimants are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		$FACTION_CLAIMANT$ = {
			has_trait = deviant
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = $FACTION_TARGET$.primary_title.state_faith GENDER_CHARACTER = $FACTION_CLAIMANT$ }
		}
		add = -20
		desc = FACTION_REASON_ADMIN_CLAIMANT_DEVIANT_AND_CRIMINAL
	}
	modifier = { # Criminal Claimants are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		$FACTION_CLAIMANT$ = {
			has_trait = incestuous
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = $FACTION_TARGET$.primary_title.state_faith GENDER_CHARACTER = $FACTION_CLAIMANT$ }
		}
		add = -20
		desc = FACTION_REASON_ADMIN_CLAIMANT_INCESTUOUS_AND_CRIMINAL
	}
	modifier = { # Criminal Claimants are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		$FACTION_CLAIMANT$ = {
			has_trait = sodomite
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = $FACTION_TARGET$.primary_title.state_faith GENDER_CHARACTER = $FACTION_CLAIMANT$ }
		}
		add = -20
		desc = FACTION_REASON_ADMIN_CLAIMANT_SODOMITE_AND_CRIMINAL
	}
	modifier = { # Criminal Claimants are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		$FACTION_CLAIMANT$ = {
			has_trait = cannibal
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = $FACTION_TARGET$.primary_title.state_faith GENDER_CHARACTER = $FACTION_CLAIMANT$ }
		}
		add = -20
		desc = FACTION_REASON_ADMIN_CLAIMANT_CANNIBAL_AND_CRIMINAL
	}
	modifier = { # Criminal Claimants are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		$FACTION_CLAIMANT$ = {
			has_trait = kinslayer_1
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = $FACTION_TARGET$.primary_title.state_faith GENDER_CHARACTER = $FACTION_CLAIMANT$ }
		}
		add = -10
		desc = FACTION_REASON_ADMIN_CLAIMANT_KINSLAYER_1_AND_CRIMINAL
	}
	modifier = { # Criminal Claimants are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		$FACTION_CLAIMANT$ = {
			has_trait = kinslayer_2
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = $FACTION_TARGET$.primary_title.state_faith GENDER_CHARACTER = $FACTION_CLAIMANT$ }
		}
		add = -20
		desc = FACTION_REASON_ADMIN_CLAIMANT_KINSLAYER_2_AND_CRIMINAL
	}
	modifier = { # Criminal Claimants are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		$FACTION_CLAIMANT$ = {
			has_trait = kinslayer_3
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = $FACTION_TARGET$.primary_title.state_faith GENDER_CHARACTER = $FACTION_CLAIMANT$ }
		}
		add = -30
		desc = FACTION_REASON_ADMIN_CLAIMANT_KINSLAYER_3_AND_CRIMINAL
	}
	modifier = { # Criminal Claimants are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		$FACTION_CLAIMANT$ = {
			has_trait = witch
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = $FACTION_TARGET$.primary_title.state_faith GENDER_CHARACTER = $FACTION_CLAIMANT$ }
		}
		add = -20
		desc = FACTION_REASON_ADMIN_CLAIMANT_WITCH_AND_CRIMINAL
	}
	modifier = { # Criminal Claimants are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		$FACTION_CLAIMANT$ = {
			has_trait = adulterer
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = $FACTION_TARGET$.primary_title.state_faith GENDER_CHARACTER = $FACTION_CLAIMANT$ }
		}
		add = -20
		desc = FACTION_REASON_ADMIN_CLAIMANT_ADULTERER_AND_CRIMINAL
	}
	modifier = { # Criminal Claimants are not desirable
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		$FACTION_CLAIMANT$ = {
			has_trait = fornicator
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = $FACTION_TARGET$.primary_title.state_faith GENDER_CHARACTER = $FACTION_CLAIMANT$ }
		}
		add = -20
		desc = FACTION_REASON_ADMIN_CLAIMANT_FORNICATOR_AND_CRIMINAL
	}
	# Born in Purple
	modifier = { # Prefer a claimant who is born in the purple when the liege is not
		ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
		$FACTION_TARGET$.primary_title = title:e_byzantium
		$FACTION_CLAIMANT$ = { has_trait = born_in_the_purple }
		NOT = {
			$FACTION_TARGET$ = { has_trait = born_in_the_purple }
		}
		add = 25
		desc = FACTION_REASON_ADMIN_BORN_IN_PURPLE
	}
	## Unpreferred heir
	#modifier = { # Admin realms have extra trouble with Unpreferred Heirs
	# 	ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
	# 	culture = { has_cultural_parameter = byzantine_faction_preffered_claimants }
	#	was_preferred_heir = $FACTION_TARGET$
	#	factor = 1.2
	#	desc = "FACTION_REASON_BYZANTINE"
	#}
	# Co-Emperor
	modifier = { # Making Claimant your Co-Emperor defuses the faction somewhat
	 	ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
	 	$FACTION_TARGET$ = {
		 	has_diarchy_type = co_emperorship
			has_active_diarchy = yes
			diarch = $FACTION_CLAIMANT$
		}
		factor = 0.5
		desc = "FACTION_REASON_ADMIN_CLAIMANT_CO_EMPEROR"
	}
	modifier = { # Making Claimant your Co-Emperor defuses the faction somewhat
	 	ep3_admin_faction_trigger = { FACTION_TARGET = $FACTION_TARGET$ } # Required for dlc context
	 	$FACTION_TARGET$ = {
		 	has_diarchy_type = junior_emperorship
			has_active_diarchy = yes
			diarch = $FACTION_CLAIMANT$
		}
		factor = 0.5
		desc = "FACTION_REASON_ADMIN_CLAIMANT_JUNIOR_EMPEROR"
	}
}
